from coresales.models import Product
from django.contrib.syndication.views import Feed
from django.core.urlresolvers import reverse
from django.utils.feedgenerator import Atom1Feed

class LatestEntriesFeed(Feed):
    title = "www.todofibrofacil.com ultimas novedades"
    link = "/sitenews/"
    description = "Ultimos cambios en www.todofibrofacil.com"
    def items(self):
        return Product.objects.filter(lastPublication=True).order_by('-countOfVisitors')[:7]

    def item_title(self, item):
        return item.name

    def item_description(self, item):
        return item.description

    # item_link is only needed if NewsItem has no get_absolute_url method.
    def item_link(self, item):
        return reverse('detailItem', kwargs={'item_slug':item.slug , 'category_slug':item.category.slug ,'catalog_slug':item.category.catalog.slug})


class AtomSiteNewsFeed(LatestEntriesFeed):
    feed_type = Atom1Feed
    subtitle = LatestEntriesFeed.description 
    